﻿var name = "somoveLanguage"; 
/*server*/
var ctx = window.document.location.href.substring(0, window.document.location.href.indexOf(window.document.location.pathname));
function chgLang() {
    var value = $("#ddlSomoveLanguage").children('option:selected').val();
    SetCookie(name, value);
    location.reload();
}
function SetCookie(name, value) {
    var Days = 30; //此 cookie 将被保存 30 天  
    var exp = new Date();    //new Date("December 31, 9998");  
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数     
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr !== null) return unescape(arr[2]); return null;
}
$(function () {
    var opts = { language: "zh",   pathPrefix: ctx + "/lang"};
  
    var uulanguage = (navigator.language || navigator.browserLanguage).toLowerCase();
    if (uulanguage.indexOf("en") > -1) {
        opts = { language: "en", pathPrefix: ctx + "/lang" };
    } else if (uulanguage.indexOf("zh") > -1) {
        opts = { language: "zh", pathPrefix: ctx + "/lang" };
    } else if (uulanguage.indexOf("ja") > -1) {
        opts = { language: "ja", pathPrefix: ctx + "/lang" };
    } else {
        opts = { language: "zh", pathPrefix: ctx + "/lang" };
    };
 
      $("[data-localize]").localize("data", opts);
    if (getCookie(name) !== "") {
        if (getCookie(name) === "zh") {
            opts = { language: "zh", pathPrefix: ctx + "/lang" };
        }
        if (getCookie(name) === "en") {
            opts = { language: "en", pathPrefix: ctx + "/lang" };
        }
        if (getCookie(name) === "ja") {
            opts = { language: "ja", pathPrefix: ctx + "/lang" };
        }
       
        $("[data-localize]").localize("data", opts); 
    }
});